
#region Using

using System;
using System.Data;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using WebLibs;

#endregion
namespace FEAT.Library
{
    /// <summary>
	/// Created by 		: Phan Hữu Hưng 
	/// Created date 	: 25/03/2010 
	/// Description 
	/// </summary>	
	public class NewsNews
	{
	
		
	
		#region Member Variables

		private int intNewsID = int.MinValue;
		private int intCategoryID = int.MinValue;
		private string strNewsTitle = string.Empty;
		private string strNewsSapo = string.Empty;
		private string strNewsContent = string.Empty;
		private string strNewsPicture = string.Empty;
		private string strNewsPictureNote = string.Empty;
		private string strNewsAuthor = string.Empty;
		private string strNewsPS = string.Empty;
		private bool bolIsShow;
		private DateTime dtmCreatedDate = DateTime.MinValue;
		private string strCreatedUser = string.Empty;
		private DateTime dtmUpdatedDate = DateTime.MinValue;
		private string strUpdatedUser = string.Empty;
		private bool bolIsDeleted;
		private DateTime dtmDeletedDate = DateTime.MinValue;
		private string strDeleteUser = string.Empty;
		private IData objDataAccess = null;


		#endregion


		#region Properties 

		public static string CacheKey
		{
  			get { return  "NewsNews_GetAll";}
		}
		/// <summary>
		/// Đối tượng Data truyền từ ngoài vào
		/// </summary>
		public IData DataObject
		{
  			get { return objDataAccess; }
   			set { objDataAccess = value; }
		}
		/// <summary>
		/// NewsID
		/// 
		/// </summary>
		public int NewsID
		{
			get { return  intNewsID; }
			set { intNewsID = value; }
		}

		/// <summary>
		/// CategoryID
		/// 
		/// </summary>
		public int CategoryID
		{
			get { return  intCategoryID; }
			set { intCategoryID = value; }
		}

		/// <summary>
		/// NewsTitle
		/// 
		/// </summary>
		public string NewsTitle
		{
			get { return  strNewsTitle; }
			set { strNewsTitle = value; }
		}

		/// <summary>
		/// NewsSapo
		/// 
		/// </summary>
		public string NewsSapo
		{
			get { return  strNewsSapo; }
			set { strNewsSapo = value; }
		}

		/// <summary>
		/// NewsContent
		/// 
		/// </summary>
		public string NewsContent
		{
			get { return  strNewsContent; }
			set { strNewsContent = value; }
		}

		/// <summary>
		/// NewsPicture
		/// 
		/// </summary>
		public string NewsPicture
		{
			get { return  strNewsPicture; }
			set { strNewsPicture = value; }
		}

		/// <summary>
		/// NewsPictureNote
		/// 
		/// </summary>
		public string NewsPictureNote
		{
			get { return  strNewsPictureNote; }
			set { strNewsPictureNote = value; }
		}

		/// <summary>
		/// NewsAuthor
		/// 
		/// </summary>
		public string NewsAuthor
		{
			get { return  strNewsAuthor; }
			set { strNewsAuthor = value; }
		}

		/// <summary>
		/// NewsPS
		/// 
		/// </summary>
		public string NewsPS
		{
			get { return  strNewsPS; }
			set { strNewsPS = value; }
		}

		/// <summary>
		/// IsShow
		/// 
		/// </summary>
		public bool IsShow
		{
			get { return  bolIsShow; }
			set { bolIsShow = value; }
		}

		/// <summary>
		/// CreatedDate
		/// 
		/// </summary>
		public DateTime CreatedDate
		{
			get { return  dtmCreatedDate; }
			set { dtmCreatedDate = value; }
		}

		/// <summary>
		/// CreatedUser
		/// 
		/// </summary>
		public string CreatedUser
		{
			get { return  strCreatedUser; }
			set { strCreatedUser = value; }
		}

		/// <summary>
		/// UpdatedDate
		/// 
		/// </summary>
		public DateTime UpdatedDate
		{
			get { return  dtmUpdatedDate; }
			set { dtmUpdatedDate = value; }
		}

		/// <summary>
		/// UpdatedUser
		/// 
		/// </summary>
		public string UpdatedUser
		{
			get { return  strUpdatedUser; }
			set { strUpdatedUser = value; }
		}

		/// <summary>
		/// IsDeleted
		/// 
		/// </summary>
		public bool IsDeleted
		{
			get { return  bolIsDeleted; }
			set { bolIsDeleted = value; }
		}

		/// <summary>
		/// DeletedDate
		/// 
		/// </summary>
		public DateTime DeletedDate
		{
			get { return  dtmDeletedDate; }
			set { dtmDeletedDate = value; }
		}

		/// <summary>
		/// DeleteUser
		/// 
		/// </summary>
		public string DeleteUser
		{
			get { return  strDeleteUser; }
			set { strDeleteUser = value; }
		}


		#endregion		
		
		
		#region Constructor

		public NewsNews()
		{
		}
		private static NewsNews _current;
		static NewsNews()
		{
			_current = new NewsNews();
		}
		public static NewsNews Current
		{
			get
			{
		      return _current;
			}
		}
		#endregion

		#region Methods	



		///<summary>
		/// Kiểm tra xem đối tượng có dữ liệu hay không
		///</summary>
		/// <returns>true ? Có : False ? Không</returns>
		public bool LoadByPrimaryKeys()
		{

			 IData objData;
			if (objDataAccess == null)
				objData = new IData();
			else
				objData = objDataAccess;
			bool bolOK = false;
			try 
			{
				if (objData.GetConnection() == null || objData.GetConnection().State == ConnectionState.Closed)
					objData.Connect();
				objData.CreateNewStoredProcedure("News_News_Select");
				objData.AddParameter("@NewsID", this.NewsID);
				IDataReader reader = objData.ExecStoreToDataReader();
				if (reader.Read())
 				{
					if(!this.IsDBNull(reader["NewsID"]))	this.NewsID = Convert.ToInt32(reader["NewsID"]);
					if(!this.IsDBNull(reader["CategoryID"]))	this.CategoryID = Convert.ToInt32(reader["CategoryID"]);
					if(!this.IsDBNull(reader["NewsTitle"]))	this.NewsTitle = Convert.ToString(reader["NewsTitle"]);
					if(!this.IsDBNull(reader["NewsSapo"]))	this.NewsSapo = Convert.ToString(reader["NewsSapo"]);
					if(!this.IsDBNull(reader["NewsContent"]))	this.NewsContent = Convert.ToString(reader["NewsContent"]);
					if(!this.IsDBNull(reader["NewsPicture"]))	this.NewsPicture = Convert.ToString(reader["NewsPicture"]);
					if(!this.IsDBNull(reader["NewsPictureNote"]))	this.NewsPictureNote = Convert.ToString(reader["NewsPictureNote"]);
					if(!this.IsDBNull(reader["NewsAuthor"]))	this.NewsAuthor = Convert.ToString(reader["NewsAuthor"]);
					if(!this.IsDBNull(reader["NewsPS"]))	this.NewsPS = Convert.ToString(reader["NewsPS"]);
					if(!this.IsDBNull(reader["IsShow"]))	this.IsShow = Convert.ToBoolean(reader["IsShow"]);
					if(!this.IsDBNull(reader["CreatedDate"]))	this.CreatedDate = Convert.ToDateTime(reader["CreatedDate"]);
					if(!this.IsDBNull(reader["CreatedUser"]))	this.CreatedUser = Convert.ToString(reader["CreatedUser"]);
					if(!this.IsDBNull(reader["UpdatedDate"]))	this.UpdatedDate = Convert.ToDateTime(reader["UpdatedDate"]);
					if(!this.IsDBNull(reader["UpdatedUser"]))	this.UpdatedUser = Convert.ToString(reader["UpdatedUser"]);
					if(!this.IsDBNull(reader["IsDeleted"]))	this.IsDeleted = Convert.ToBoolean(reader["IsDeleted"]);
					if(!this.IsDBNull(reader["DeletedDate"]))	this.DeletedDate = Convert.ToDateTime(reader["DeletedDate"]);
					if(!this.IsDBNull(reader["DeleteUser"]))	this.DeleteUser = Convert.ToString(reader["DeleteUser"]);
 					bolOK = true;
 				}
				reader.Close();
			}
			catch (Exception objEx)
			{
				throw new Exception("LoadByPrimaryKeys() Error   " + objEx.Message.ToString());
			}
			finally
    		{
    			if (objDataAccess == null)
        			objData.DeConnect();
    		}
    		return bolOK;
		}

		///<summary>
		/// Insert : News_News
		/// Them moi du lieu
		///</summary>
		public object Insert()
		{
			 IData objData;
			if (objDataAccess == null)
				objData = new IData();
			else
				objData = objDataAccess;
			object objTemp = null;
			try 
			{
				if (objData.GetConnection() == null || objData.GetConnection().State == ConnectionState.Closed)
					objData.Connect();
				objData.CreateNewStoredProcedure("News_News_Insert");
				if(this.NewsID != int.MinValue) objData.AddParameter("@NewsID", this.NewsID);
				if(this.CategoryID != int.MinValue) objData.AddParameter("@CategoryID", this.CategoryID);
				objData.AddParameter("@NewsTitle", this.NewsTitle);
				objData.AddParameter("@NewsSapo", this.NewsSapo);
				objData.AddParameter("@NewsContent", this.NewsContent);
				objData.AddParameter("@NewsPicture", this.NewsPicture);
				objData.AddParameter("@NewsPictureNote", this.NewsPictureNote);
				objData.AddParameter("@NewsAuthor", this.NewsAuthor);
				objData.AddParameter("@NewsPS", this.NewsPS);
				objData.AddParameter("@IsShow", this.IsShow);
				objData.AddParameter("@CreatedUser", this.CreatedUser);
				objData.AddParameter("@DeleteUser", this.DeleteUser);
                objTemp = objData.ExecStoreToString();
			}
			catch (Exception objEx)
			{
				throw new Exception("Insert() Error   " + objEx.Message.ToString());
			}
			finally
    		{
    			if (objDataAccess == null)
        			objData.DeConnect();
    		}
    		return objTemp;
		}


		///<summary>
		/// Update : News_News
		/// Cap nhap thong tin
		///</summary>
		public object Update()
		{
			 IData objData;
			if (objDataAccess == null)
				objData = new IData();
			else
				objData = objDataAccess;
			object objTemp = null;
			try 
			{
				if (objData.GetConnection() == null || objData.GetConnection().State == ConnectionState.Closed)
					objData.Connect();
				objData.CreateNewStoredProcedure("News_News_Update");
				if(this.NewsID != int.MinValue)	objData.AddParameter("@NewsID", this.NewsID);
				else objData.AddParameter("@NewsID", DBNull.Value);
				if(this.CategoryID != int.MinValue)	objData.AddParameter("@CategoryID", this.CategoryID);
				else objData.AddParameter("@CategoryID", DBNull.Value);
				objData.AddParameter("@NewsTitle", this.NewsTitle);
				objData.AddParameter("@NewsSapo", this.NewsSapo);
				objData.AddParameter("@NewsContent", this.NewsContent);
				objData.AddParameter("@NewsPicture", this.NewsPicture);
				objData.AddParameter("@NewsPictureNote", this.NewsPictureNote);
				objData.AddParameter("@NewsAuthor", this.NewsAuthor);
				objData.AddParameter("@NewsPS", this.NewsPS);
				objData.AddParameter("@IsShow", this.IsShow);
				objData.AddParameter("@UpdatedUser", this.UpdatedUser);
				objData.AddParameter("@DeleteUser", this.DeleteUser);
                objTemp = objData.ExecNonQuery();
			}
			catch (Exception objEx)
			{
				throw new Exception("Update() Error   " + objEx.Message.ToString());
			}
			finally
    		{
    			if (objDataAccess == null)
        			objData.DeConnect();
    		}
    		return objTemp;
		}


		///<summary>
		/// Delete : News_News
		///
		///</summary>
		public int Delete()
		{

			 IData objData;
			if (objDataAccess == null)
				objData = new IData();
			else
				objData = objDataAccess;
			int intTemp = 0;
			try 
			{
				if (objData.GetConnection() == null || objData.GetConnection().State == ConnectionState.Closed)
					objData.Connect();
				objData.CreateNewStoredProcedure("News_News_Delete");
				objData.AddParameter("@NewsID", this.NewsID);
 				intTemp = objData.ExecNonQuery();
			}
			catch (Exception objEx)
			{
				throw new Exception("Delete() Error   " + objEx.Message.ToString());
			}
			finally
    		{
    			if (objDataAccess == null)
        			objData.DeConnect();
    		}
    		return intTemp;
		}


		///<summary>
		/// Get all : News_News
		///
		///</summary>
		public DataTable GetAll()
		{

			 IData objData;
			if (objDataAccess == null)
				objData = new IData();
			else
				objData = objDataAccess;
			try
			{
				if (objData.GetConnection() == null || objData.GetConnection().State == ConnectionState.Closed)
					objData.Connect();
				objData.CreateNewStoredProcedure("News_News_SelectAll");
				return objData.ExecStoreToDataTable();
			}
			catch (Exception objEx)
			{
				throw new Exception("GetAll() Error   " + objEx.Message.ToString());
			}
			finally
			{
    		 if (objDataAccess == null)
        		objData.DeConnect();
			}
		}
		#endregion


		/// <summary>
        /// Check Data IsDBNull 
        /// </summary>
        /// <param name="objObject"> Object Value</param>
        /// <returns>Null : true ? false </returns>
		private bool IsDBNull(object objObject)
		{
			return Convert.IsDBNull(objObject);
		}
		
		
		/******************************************************
		 	News_News objNews_News = new News_News();
			objNewsNews.NewsID = txtNewsID.Text;
			objNewsNews.CategoryID = txtCategoryID.Text;
			objNewsNews.NewsTitle = txtNewsTitle.Text;
			objNewsNews.NewsSapo = txtNewsSapo.Text;
			objNewsNews.NewsContent = txtNewsContent.Text;
			objNewsNews.NewsPicture = txtNewsPicture.Text;
			objNewsNews.NewsPictureNote = txtNewsPictureNote.Text;
			objNewsNews.NewsAuthor = txtNewsAuthor.Text;
			objNewsNews.NewsPS = txtNewsPS.Text;
			objNewsNews.IsShow = txtIsShow.Text;
			objNewsNews.CreatedDate = txtCreatedDate.Text;
			objNewsNews.CreatedUser = txtCreatedUser.Text;
			objNewsNews.UpdatedDate = txtUpdatedDate.Text;
			objNewsNews.UpdatedUser = txtUpdatedUser.Text;
			objNewsNews.IsDeleted = txtIsDeleted.Text;
			objNewsNews.DeletedDate = txtDeletedDate.Text;
			objNewsNews.DeleteUser = txtDeleteUser.Text;

		 
		 ******************************************************
		 
		 			txtNewsID.Text = objNewsNews.NewsID;
			txtCategoryID.Text = objNewsNews.CategoryID;
			txtNewsTitle.Text = objNewsNews.NewsTitle;
			txtNewsSapo.Text = objNewsNews.NewsSapo;
			txtNewsContent.Text = objNewsNews.NewsContent;
			txtNewsPicture.Text = objNewsNews.NewsPicture;
			txtNewsPictureNote.Text = objNewsNews.NewsPictureNote;
			txtNewsAuthor.Text = objNewsNews.NewsAuthor;
			txtNewsPS.Text = objNewsNews.NewsPS;
			txtIsShow.Text = objNewsNews.IsShow;
			txtCreatedDate.Text = objNewsNews.CreatedDate;
			txtCreatedUser.Text = objNewsNews.CreatedUser;
			txtUpdatedDate.Text = objNewsNews.UpdatedDate;
			txtUpdatedUser.Text = objNewsNews.UpdatedUser;
			txtIsDeleted.Text = objNewsNews.IsDeleted;
			txtDeletedDate.Text = objNewsNews.DeletedDate;
			txtDeleteUser.Text = objNewsNews.DeleteUser;

		 
		*******************************************************/
		
	}
}
